

using System;

class Exercise3 {
    
  static int playerScore = 0;

  static int Main() {
      
      byte option = 0;
      
      do{
          Console.Clear();
          printMenu();
          Console.Write("Enter a command: ");
          try{
              
              option = Convert.ToByte(Console.ReadLine());
              
              switch(option){
                  
                  case (1): //start the game
                           Console.Clear();
                           playerScore += startGame(); //updating the player score
                           break;
                  case (2): //withdraw the money and exit
                          Console.WriteLine("\nThank you for playing with me!\nToday you bring home: {0}\n", playerScore);
                          break;
                  case (3):
                          return(0); //terminates the program
                          break;
                  default:
                         Console.WriteLine("\nError while reading the option!\n");
                         break;
              }
              
          }catch(Exception){
              
              Console.WriteLine("\nError while reading the option!\n");
              
          }
          Console.Write("Press a key to proceede");
          Console.ReadKey(); 
      }while(option != 2); //continue the loop until the user decides to quit the game
      
      return(0); //terminates the program
  }
  
  private static void printMenu(){
      
      Console.WriteLine("********************************");
      Console.WriteLine("*     Fruit Machine Game       *");
      Console.WriteLine("*      Stefan Dinovsky         *");
      Console.WriteLine("********************************");
      
      Console.WriteLine("--------------------------------");
      Console.WriteLine("|             MENU             |");
      Console.WriteLine("--------------------------------");
      Console.WriteLine("|           1 - Spin           |");
      Console.WriteLine("|     2 - Take your money!     |");
      Console.WriteLine("|        3 - Quit Game         |");
      Console.WriteLine("--------------------------------");
      Console.WriteLine("\nSCORE: {0}\n", playerScore);
  }
  
  private static int startGame(){ //generates the random combination and return the score
  
  int score = 0;
  
  Random r = new Random(); //creating a random object for the generation of the number
  
  byte seed1 = (byte)r.Next(0, 10); //generating the 1st random number
  byte seed2 = (byte)r.Next(0, 10); //generating the 2nd random number
  byte seed3 = (byte)r.Next(0, 10); //generating the 3rd random number
  
  
  if (seed1 != 9 && seed2 != 9 && seed3 != 9 && (seed1 == seed2 || seed1 == seed3 || seed2 == seed3)){ //combination of 2 equal numbers excluding the nines
  
      score += 5;
  
  }else if(seed1 != 9 && seed2 != 9 && seed3 != 9 && (seed1 == seed2 && seed1 == seed3)){ //combination of 3 equal numbers excluding nines
  
      score += 15;
  
  }else if((seed1 == 9 && seed2 == 9 && seed3 != 9) || (seed1 != 9 && seed2 == 9 && seed3 == 9) || (seed1 == 9 && seed2 != 9 && seed3 == 9)){ //combination of 2 nines
      
      score += 200;
  
  }else if(seed1 == 9 && seed2 == 9 && seed3 == 9){ //combination of 3 nines
      
      score += 2000;
      
  }
  
      Console.WriteLine("\n--------------------------------");
      Console.WriteLine("|         COMBINATION          |");
      Console.WriteLine("|          {0} - {1} - {2}           |", seed1, seed2, seed3);
      Console.WriteLine("--------------------------------");
      Console.WriteLine("\nPoints gained: {0}\n", score);
  
  return(score); //return score
  
  }

}